package com.lz.config;

import com.lz.properties.OSSProperties;
import com.lz.util.OSSUtil;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * <pre>
 * @描述：
 * @作者：lizhao
 * @创建时间： 2024/9/19 下午3:21
 * </pre>
 **/
@Component
@ConfigurationProperties(prefix = "aliyun.oss")
public class OSSAutoConfiguretion {
    private String endpoint;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;

    public OSSAutoConfiguretion() {
    }

    public OSSAutoConfiguretion(String endpoint, String accessKeyId, String accessKeySecret, String bucketName) {
        this.endpoint = endpoint;
        this.accessKeyId = accessKeyId;
        this.accessKeySecret = accessKeySecret;
        this.bucketName = bucketName;
    }

    @Bean
    @ConditionalOnProperty(prefix = "aliyun.oss", name = {"endpoint", "accessKeyId", "accessKeySecret", "bucketName"})
    public OSSUtil ossUtil() {
        OSSProperties ossProperties = new OSSProperties(endpoint, accessKeyId, accessKeySecret, bucketName);
        OSSUtil ossUtil = new OSSUtil();
        ossUtil.setOSSProperties(ossProperties);
        return ossUtil;
    }

    /**
     * 获取
     *
     * @return endpoint
     */
    public String getEndpoint() {
        return endpoint;
    }

    /**
     * 设置
     *
     * @param endpoint
     */
    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    /**
     * 获取
     *
     * @return accessKeyId
     */
    public String getAccessKeyId() {
        return accessKeyId;
    }

    /**
     * 设置
     *
     * @param accessKeyId
     */
    public void setAccessKeyId(String accessKeyId) {
        this.accessKeyId = accessKeyId;
    }

    /**
     * 获取
     *
     * @return accessKeySecret
     */
    public String getAccessKeySecret() {
        return accessKeySecret;
    }

    /**
     * 设置
     *
     * @param accessKeySecret
     */
    public void setAccessKeySecret(String accessKeySecret) {
        this.accessKeySecret = accessKeySecret;
    }

    /**
     * 获取
     *
     * @return bucketName
     */
    public String getBucketName() {
        return bucketName;
    }

    /**
     * 设置
     *
     * @param bucketName
     */
    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }

    public String toString() {
        return "OSSAutoConfiguretion{endpoint = " + endpoint + ", accessKeyId = " + accessKeyId + ", accessKeySecret = " + accessKeySecret + ", bucketName = " + bucketName + "}";
    }
}
